package com.roast.pages;

import java.util.List;
import com.roast.domain.Address;
import com.roast.services.my.MyServicesFacade;
import com.roast.util.EventSSO;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;

public class PublicEvent {

    @SessionState
    @Property
    private EventSSO eventSSO;

    @Property
    String systemMessage = "     ";

    @Property
    Address address;

    @Inject
    MyServicesFacade myServices;

    public List<Address> getAddressList() {
        try {
            List<Address> list = eventSSO.getAddressList();
            if (!list.isEmpty()) {
                return list;
            }
        } catch (Exception e) {
            System.out.println("[PAGE:ShowUserEvent:" + e + "]");
        }
        return null;
    }

    public boolean isNoAddressingsTest() {
        return getAddressList() == null;
    }

    @InjectPage
    private PublicComments showComments;

    @OnEvent(component = "commentLink")
    Object onShowComments(long id) {
        Address addressShow = new Address();
        addressShow.setAddressID(id);

        int signal = myServices.getAddress(addressShow);

        if (signal == 10900) {
            showComments.setAddress(addressShow);
            return showComments;
        }
        systemMessage = "Fail to show comments!";
        return PublicEvent.class;
    }

    void onActivate(String systemMessage) {
        this.systemMessage = systemMessage;
    }

    String onPassivate() {
        return systemMessage;
    }
}
